
global.L.Canvas.include({
  
  _update: function () {
    if (this._map._animatingZoom && this._bounds) { return; }

    this._drawnLayers = {};

    global.L.Renderer.prototype._update.call(this);

    var b = this._bounds,
      container = this._container,
      size = b.getSize();

    // setPosition(container, b.min);

    // set canvas size (also clearing it); use double size on retina
    container.width = size.x;
    container.height = size.y;
    container.position = b.min;
    // translate so we use the same path coordinates after canvas element moves

    // Tell paths to redraw themselves
    this.fire('update');
  },
  
  _draw: function () {
    var layer, bounds = this._redrawBounds;
    this._ctx.save();
    if (bounds) {
      var size = bounds.getSize();
      this._ctx.beginPath();
      this._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);
      this._ctx.clip();
    }


    let container = this._container
    let that = this
    global.wxDOM.setOverlayCanvasPositionAndSize(
      container.width, container.height, container.position, () => {
        global.L.Util.waitWxDomReadyFrame(() => {
          that._drawing = true;
          that._ctx.translate(-container.position.x, -container.position.y);
          for (var order = that._drawFirst; order; order = order.next) {
            layer = order.layer;
            if (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) {
              layer._updatePath();
            }
          }
          that._drawing = false;
          that._ctx.restore();  // Restore state before clipping.
        })
      });
  },

  _updatePoly: function (layer, closed) {
    if (!this._drawing) { return; }

    var i, j, len2, p,
      parts = layer._parts,
      len = parts.length,
      ctx = this._ctx;

    if (!len) { return; }

    this._drawnLayers[layer._leaflet_id] = layer;

    ctx.beginPath();

    for (i = 0; i < len; i++) {
      for (j = 0, len2 = parts[i].length; j < len2; j++) {
        p = parts[i][j];
        ctx[j ? 'lineTo' : 'moveTo'](p.x, p.y);
      }
      if (closed) {
        ctx.closePath();
      }
    }

    this._fillStroke(ctx, layer);

    // TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature
  },  
})